package UI.Main;

import BLL.*;
import UI.MultiPlayer.*;
import UI.Main.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import java.io.File;
import java.io.IOException;

import java.text.DecimalFormat;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.filechooser.FileSystemView;

/**
 * @author 杨明政
 * @version  2021.0510
 * @since 1.8
 */

/**
 * 主页面类.
 * For example:
 * <pre>
 * MainForm f=new MainForm();
 * </pre>
 * @author 杨明政
 * @see java.util.EventListener
 */
public class MainForm extends JPanel implements ActionListener{
    public static MainForm _instance;
    //文件类型归类
    public static List<String> VideoType = Arrays.asList("avi","wmv","rm","rmvb","mpeg1","mpeg2","mpeg4","mp4","3gp","asf","swf","vob","dat","mov","m4v","flv","f4v","mkv","mts","ts","qsv","AVI","WMV","RM","RMVB","MPEG1","MPEG2","MPEG4","MP4","3GP","ASF","SWF","VOB","DAT","MOV","M4V","FLV","F4V","MKV","MTS","TS","QSV");
    public static List<String> GraphType = Arrays.asList("bmp","gif","jpeg","jpeg2000","tiff","psd","png","swf","svg","pcx","dxf","wmf","emf","lic","eps","tga","jpg","BMP","GIF","JPEG","JPEG2000","TIFF","PSD","PNG","SWF","SVG","PCX","DXF","WMF","EMF","LIC","EPS","TGA","JPG");
    public static List<String> TxtType = Arrays.asList("txt","doc","docx","wps","pdf","chm","pdg","wdl","xls","xlsx","ppt","pptx","java","c","cpp","py");
    public static List<String> MusicType = Arrays.asList("m4a","cd","wave","wav","aiff","au","mp3","midi","wma","aac","ape","CD","WAVE","WAV","AIFF","AU","MP3","MIDI","WMA","RealAudio","VQF","OggVorbis","AAC","APE");
    public static FileProperties properties;

    //主页面组件
    JPanel p, SortPanel, ShowPanel, FunctPanel, TreePanel,test,ViewPanel,choosePanel,infoPanel;
    JScrollPane ScrollShow;
    JButton PreBtn, LatBtn, GoBtn,ViewBtn,infobtn,vedioType,textType,pictureType,musicType,allType;
    public static int chooseType=5;
    JTextField SearchText, GuideText;
    JCheckBox FileCheck, DirCheck;
    public static String Cur_URL = "";
    public static String aimFile="";
    String Pre_URL = "";
    String LatURL = "";
    public static Map<String, String> Maps = new HashMap<String,String>();
    public static JList<String> list;
    public DefaultListModel defaultListModel;
    public Stack<String> stack, stack_return;
    JPopupMenu jPopupMenu = null;
    JPopupMenu jPopupMenu2 = null;
    JPopupMenu jPopupMenu3 = null;
    JMenuItem[] JMIs = new JMenuItem[10];
    JMenuItem[] JMIs2 = new JMenuItem[5];
    JMenuItem delete = new JMenuItem("删除");
    public Icon[] AllIcons = new Icon[1000010];//存储搜索得到的文件图标
    public int Icon_Counter = 0;
    //保存GB,MB,KB,B对应的字节数，方便换算文件大小及单位
    long[] Sizes = {1073741824,1048576,1024,1};
    String[] Size_Names = {"GB", "MB", "KB", "B"};
    public static Boolean  isSearching = false;

    /**
     * 软件主窗口构造函数
     */
    public MainForm(){//主界面
        this._instance=this;
        this.setBounds(0, 0, 1210, 900);
        this.setLayout(null);
        Init();
        this.setVisible(false);
    }
    /**
     * 显示当前选择显示的文件类型
     */
    private void showTpye()
    {
        vedioType.setBackground(Color.gray); //mode1
        vedioType.setForeground(Color.white);
        textType.setBackground(Color.gray);  //mode2
        textType.setForeground(Color.white);
        pictureType.setBackground(Color.gray); //mode3
        pictureType.setForeground(Color.white);
        musicType.setBackground(Color.gray);// mode4
        musicType.setForeground(Color.white);
        allType.setBackground(Color.gray); //mode5
        allType.setForeground(Color.white);
        if(chooseType==1)
        {
            vedioType.setBackground(Color.white);
            vedioType.setForeground(Color.black);
        }
        if(chooseType==2)
        {
            textType.setBackground(Color.white);
            textType.setForeground(Color.black);
        }
        if(chooseType==3)
        {
            pictureType.setBackground(Color.white);
            pictureType.setForeground(Color.black);
        }
        if(chooseType==4)
        {
            musicType.setBackground(Color.white);
            musicType.setForeground(Color.black);
        }
        if(chooseType==5)
        {
            allType.setBackground(Color.white);
            allType.setForeground(Color.black);
        }
        
    }
    /**
     * 主窗口组件初始化
     */
    public void Init(){
        //各个panel初始化
        choosePanel=new JPanel();
        choosePanel.setLayout(null);
        this.add(choosePanel);
        choosePanel.setBounds(0,50,610,50);
        choosePanel.setBackground(Color.lightGray);
        vedioType=new JButton("视频");
        textType=new JButton("文本");
        pictureType=new JButton("图片");
        musicType=new JButton("音乐");
        allType=new JButton("全部");
        
        vedioType.addActionListener(this);
        vedioType.setBounds(129,0,120,50);
        vedioType.setFont(new  java.awt.Font("宋体",  1,  28));
        vedioType.setBackground(Color.gray);
        vedioType.setForeground(Color.white);
        textType.addActionListener(this);
        textType.setBounds(249,0,120,50);
        textType.setFont(new  java.awt.Font("宋体",  1,  28));
        textType.setBackground(Color.gray);
        textType.setForeground(Color.white);
        
        pictureType.addActionListener(this);
        pictureType.setBounds(369,0,120,50);
        pictureType.setFont(new  java.awt.Font("宋体",  1,  28));
        pictureType.setBackground(Color.gray);
        pictureType.setForeground(Color.white);
        
        musicType.addActionListener(this);
        musicType.setBounds(489,0,120,50);
        musicType.setFont(new  java.awt.Font("宋体",  1,  28));
        musicType.setBackground(Color.gray);
        musicType.setForeground(Color.white);
        
        allType.addActionListener(this);
        allType.setBounds(0,0,129,50);
        allType.setFont(new  java.awt.Font("宋体",  1,  28));
        allType.setBackground(Color.gray);
        allType.setForeground(Color.white);
        
        choosePanel.add(vedioType);
        choosePanel.add(textType);
        choosePanel.add(musicType);
        choosePanel.add(pictureType);
        choosePanel.add(allType);
        showTpye();
        
        p = new JPanel();
        SortPanel = new JPanel();
        ShowPanel = new JPanel();
        FunctPanel = new JPanel();
        TreePanel = new JPanel();
        test=new JPanel();
        
        //顶部查询搜索模块
        SortPanel.setSize(200, 80);
        SortPanel.setLayout(new FlowLayout());
        SortPanel.setBackground(Color.lightGray);
        
        //前进后退按钮
        PreBtn = new JButton("<<");
        PreBtn.setFont(new Font("Serif", Font.PLAIN, 28));
        PreBtn.setBounds(0, 0, 100, 50);
        PreBtn.addActionListener(this);
        PreBtn.setBackground(Color.gray);
        PreBtn.setForeground(Color.white);
        PreBtn.setBorder(BorderFactory.createLineBorder(Color.white));
        
        LatBtn = new JButton(">>");
        LatBtn.setFont(new Font("Serif", Font.PLAIN, 28));
        LatBtn.setBounds(100, 0, 100, 50);
        LatBtn.addActionListener(this);
        LatBtn.setBackground(Color.gray);
        LatBtn.setForeground(Color.white);
        LatBtn.setBorder(BorderFactory.createLineBorder(Color.white));
        
        
        //导航栏
        FunctPanel = new JPanel();
        FunctPanel.setBounds(0, 0, 1410, 50);
        FunctPanel.setLayout(null);
        FunctPanel.setBackground(Color.gray);
        GuideText = new JTextField();
        GuideText.setBounds(150, 0, 550, 50);
        GuideText.addActionListener(this);
        GuideText.setFont(new  java.awt.Font("宋体",  1,  28));
        GoBtn = new JButton("→");
        GoBtn.setFont(new Font("Serif", Font.PLAIN, 28));
        GoBtn.setBounds(700, 0, 80, 50);
        GoBtn.addActionListener(this);
        GoBtn.setBackground(Color.gray);
        GoBtn.setForeground(Color.white);
        ViewBtn=new JButton("预览");
        ViewBtn.setBounds(810,0,120,50);
        ViewBtn.setFont(new  java.awt.Font("宋体",  1,  28));
        ViewBtn.setBackground(Color.gray);
        ViewBtn.setForeground(Color.white);
        ViewBtn.addActionListener(this);
        ViewBtn.setBorder(BorderFactory.createLineBorder(Color.white));
        infobtn=new JButton("信息");
        infobtn.setBounds(930,0,120,50);
        infobtn.setFont(new  java.awt.Font("宋体",  1,  28));
        infobtn.setBackground(Color.gray);
        infobtn.setForeground(Color.white);
        infobtn.addActionListener(this);
        infobtn.setBorder(BorderFactory.createLineBorder(Color.white));
        
        UserPage._instance.add(PreBtn);
        UserPage._instance.add(LatBtn);
        FunctPanel.add(GuideText);
        FunctPanel.add(GoBtn);
        FunctPanel.add(ViewBtn);
        FunctPanel.add(infobtn);
        this.add(FunctPanel);
        
        //中部文件列表
        stack = new Stack<String>();
        stack_return = new Stack<String>();
        list = new JList<String>();
        jPopupMenu = new JPopupMenu();//文件/文件夹的属性菜单
        jPopupMenu2 = new JPopupMenu();//磁盘的属性菜单
        JMIs[0] = new JMenuItem("打开");
        JMIs[1] = new JMenuItem("删除");
        JMIs[2] = new JMenuItem("重命名");
        for(int k = 0; k < 3; ++k){//文件/文件夹的属性菜单初始化
            JMIs[k].addActionListener(this);
            jPopupMenu.add(JMIs[k]);
        }
        JMIs2[0] = new JMenuItem("打开");//磁盘的属性菜单初始化
        JMIs2[0].addActionListener(this);
        jPopupMenu2.add(JMIs2[0]);
        jPopupMenu3 = new JPopupMenu();
        delete.addActionListener(this);
        jPopupMenu3.add(delete);
        list.add(jPopupMenu3);
        list.add(jPopupMenu2);
        list.add(jPopupMenu);
        Home_List();//显示磁盘根目录
        list.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e){
                if(list.getSelectedIndex() != -1){
                    if(e.getClickCount() == 1){//单击list时，暂无事件
                        oneClick(list.getSelectedValue());
                    }else if(e.getClickCount() == 2){//双击list时，打开文件或进入该子目录
                        System.out.println(list.getSelectedValue());
                        twoClick(list.getSelectedValue());
                    }
                    if(e.getButton() == 3){//右击list时，打开菜单栏
                        if(Cur_URL != ""){
                            if(list.getSelectedValuesList().size() == 1){
                                jPopupMenu.show(list,e.getX(),e.getY()); //如果右击的是单个文件夹和文件，则应打开一个功能齐全的菜单栏
                            }else if(list.getSelectedValuesList().size() > 1){//如果选中多个文件夹和文件，则只支持删除功能
                                jPopupMenu3.show(list, e.getX(), e.getY());
                            }
                        }
                        else if(Cur_URL == "" && list.getSelectedValuesList().size() == 1){
                            jPopupMenu2.show(list, e.getX(), e.getY());
                        }
                    }
                }
            }
        });
        ScrollShow = new JScrollPane(list);
        ScrollShow.setBounds(0,99,610,755);
        this.add(ScrollShow);
    }
    /**
     * 单击
     * @param choice 当前选择的文件名
     */
    private void oneClick(String choice){//点击一次的方法
        File file = new File(Cur_URL + choice);
        aimFile=Cur_URL+choice;
    }
    /**
     * 单击
     * @param choice 当前选择的文件名
     */
    public void twoClick(String choice){//点击两次时的事件
        choice += "\\";
        File cur_file = new File(Cur_URL);
        if(cur_file.isDirectory())
        {
            if(Cur_URL.charAt(Cur_URL.length() - 1) != '\\')
                Cur_URL += '\\';
        }

        File file = new File(Cur_URL + choice);
        if(file.isDirectory()){
            Cur_URL += choice;
            stack.push(Cur_URL);
            Go_There();//如果双击文件夹进入文件夹下
        }else{
            OpenIt(file);//如果双击文件则打开文件
        }
    }
    /**
     * 初始磁盘界面函数
     */
    public void Home_List(){//回到初始磁盘界面
        List<String> Disks = MemoryInfo.getDisk();
        defaultListModel = new DefaultListModel();
        for(int i = 0; i < Disks.size(); ++i){
            defaultListModel.addElement(Disks.get(i));
        }
        Icon[] icons = FileIcon.getAllIcon("HOME");//得到根目录下的图标
        list.setModel(defaultListModel);
        list.setCellRenderer(new UI.Main.MyCellRenderer(icons));
        GuideText.setText("");
        Cur_URL = "";//重置当前路径
        stack.push(Cur_URL);
    }
    /**
     * 单击
     * @param file 要打开的文件
     */
    public void OpenIt(File file){
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    /**
     * 跳转到选择的路径下
     */
    public void Go_There(){//跳转函数
        GuideText.setText(Cur_URL);
        if(Cur_URL != ""){//Cur_URL非空，就跳入目标目录
            defaultListModel.clear();
            String[] getString = FileName.getName(Cur_URL);
            for(int i = 0; i < getString.length; ++i){
                defaultListModel.addElement(getString[i]);
            }
            Icon[] icons = FileIcon.getAllIcon(Cur_URL);
            list.setModel(defaultListModel);
            list.setCellRenderer(new UI.Main.MyCellRenderer(icons));
            
        }else{//Cur_URL为空时，就跳转回根目录
            Home_List();
        }
    }
    /**
     * 单击
     * @param path 当前需要筛选内容文件路径
     */
    public void GetAllResults(String path){//搜索功能核心函数
        if(path != ""){
            String[] getString = FileName.getName(path);
            for(int i = 0; i < getString.length; ++i){
                File file = new File(path + getString[i] + "\\");
                if(file.isDirectory()){
                    continue;
                }else{
                    String prefix = getString[i].substring(getString[i].lastIndexOf('.') + 1);
                    if(VideoType.contains(prefix) && chooseType==1){//判断是否为视频文件且视频按钮被选中，是则加入我们的显示目录里
                        System.out.println(getString[i]);
                        defaultListModel.addElement(getString[i]);
                        AllIcons[Icon_Counter++] = FileIcon.getIcon(path + getString[i]);
                    }else if(GraphType.contains(prefix) && chooseType==3){//判断是否为图片文件且图片按钮被选中，是则加入我们的显示目录里
                        defaultListModel.addElement(getString[i]);
                        AllIcons[Icon_Counter++] = FileIcon.getIcon(path + getString[i]);
                    }else if(TxtType.contains(prefix) && chooseType==2){//判断是否为文档文件且文档按钮被选中，是则加入我们的显示目录里
                        defaultListModel.addElement(getString[i]);
                        AllIcons[Icon_Counter++] = FileIcon.getIcon(path + getString[i]);
                    }else if(MusicType.contains(prefix) && chooseType==4){//判断是否为音乐文件且文档按钮被选中，是则加入我们的显示目录里
                        defaultListModel.addElement(getString[i]);
                        AllIcons[Icon_Counter++] = FileIcon.getIcon(path + getString[i]);
                    }
                }
            }
        }
    }


    /**
     * 动作处理
     * @param e 动作事件
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        if(e.getSource() == PreBtn){//返回上一级目录
            LatURL = Cur_URL;
            if(!stack.isEmpty()){
                stack.pop();//每从当前一个目录跳回之前的目录时，stack就要出栈
                stack_return.push(Cur_URL);//把跳之前的目录放入返回栈stack_return
                if(!stack.isEmpty()){
                    Cur_URL = stack.peek();//从栈中得到上一个访问的目录，赋给当前目录
                }
                else{
                    Cur_URL = "";//如果栈为空，则说明前面是根目录，则直接置空
                }
                Go_There();
            }
        }
        
        else if(e.getSource() == LatBtn){//与返回上一级目录相反的操作
            if(!stack_return.isEmpty()){//则从返回栈里拿URL
                Cur_URL = stack_return.peek();
                stack_return.pop();
                stack.push(Cur_URL);
                Go_There();
            }
        }
        
        else if(e.getSource() == JMIs[0] || e.getSource() == JMIs2[0]){	//打开文件/文件夹/磁盘
            String url = Cur_URL + list.getSelectedValue();
            if(Cur_URL != ""){
                url += "\\";
            }
            File file = new File(url);
            if(file.isDirectory()){
                twoClick(list.getSelectedValue());
            }else{
                OpenIt(file);
            }

        }
        
        else if(e.getSource() == JMIs[1]){//删除
            File file = new File(Cur_URL + "/" + list.getSelectedValue());
            int n;
            if(file.isFile()){
                n = JOptionPane.showConfirmDialog(null, "确定要删除文件 " + file.getName() + " 么?", "文件删除",JOptionPane.YES_NO_OPTION);
            }else{
                n = JOptionPane.showConfirmDialog(null, "确定要删除 " + file.getName() + " 及其目录下的文件么?", "文件夹删除",JOptionPane.YES_NO_OPTION);
            }
            if(n == 0){
                FileDelete.Delete(Cur_URL + list.getSelectedValue() +  "\\");
                Go_There();
            }
        }
        
        else if(e.getSource() == delete){//多选下的删除
            List<String> selected_str = list.getSelectedValuesList();
            File file;
            int num = selected_str.size();
            int n = JOptionPane.showConfirmDialog(null, "确定要删除 " + selected_str.get(0) + " 等" + num + "项么?", "文件删除",JOptionPane.YES_NO_OPTION);
            if(n == 0){
                for(int i = 0; i < selected_str.size(); ++i){
                    FileDelete.Delete(Cur_URL + selected_str.get(i) +  "\\");
                }
                Go_There();
            }
        }
        
        else if(e.getSource() == JMIs[2]){//重命名
            String before = list.getSelectedValue();
            File file = new File(Cur_URL + before + "\\");
            String after = "";
            if(file.isDirectory()){
                after = (String) JOptionPane.showInputDialog(null, "请输入新文件夹名:\n", "重命名", JOptionPane.PLAIN_MESSAGE, null, null,
                        list.getSelectedValue());
            }else{
                after = (String) JOptionPane.showInputDialog(null, "请输入新文件名:\n", "重命名", JOptionPane.PLAIN_MESSAGE, null, null,
                        list.getSelectedValue());
            }
            if(before != after && after != null){
                new File(Cur_URL + before + "\\").renameTo(new File(Cur_URL + after + "\\"));
                Go_There();
            }else{
                Go_There();
            }
        }
        
        else if(e.getSource() == JMIs[3]){//打开文件/文件夹属性窗口
            String temp_url = Cur_URL + list.getSelectedValue() + "\\";
            File file = new File(temp_url);
            Icon icon = FileIcon.getIcon(temp_url);
            String name = list.getSelectedValue();
            long size;
            double final_size;
            long File_Num = 0, Directory_Num = 0;
            int flag = 0;
            String file_size = "";
            
            String Create_Time = FileTime.CreateTime(temp_url);
            String Modify_Time = FileTime.UpdateTime(temp_url);
            String Last_Access = FileTime.AccessTime(temp_url);
            
            if(file.isDirectory()){//目录属性初始化所需参数
                FileInfo DInfo = new FileInfo();
                size = DInfo.instance.getSize(file);
                File_Num = DInfo.file_num;
                Directory_Num = DInfo.dir_num;
                flag = 1;
            }else{//文件属性初始化所需参数
                size = file.length();
            }
            final_size = 0;
            for(int i = 0; i < Sizes.length; ++i){
                if(size / Sizes[i] > 0){
                    final_size = size * 1.0 / Sizes[i];
                    DecimalFormat fnum = new DecimalFormat("##0.00");
                    file_size = fnum.format(final_size) + Size_Names[i];
                    break;
                }
            }
            if(flag == 1){
                UI.Main.FileProperties properties = new FileProperties(icon, name, file_size, File_Num, Directory_Num-1, temp_url, Create_Time);
            }else{
                UI.Main.FileProperties properties = new FileProperties(icon, name, file_size, temp_url, Create_Time, Modify_Time, Last_Access);
            }
        }
        
        else if(e.getSource() == JMIs2[1]){//磁盘属性查看
            String temp_url = list.getSelectedValue() + "\\";
            System.out.println(temp_url);
            Icon icon = FileIcon.getIcon(temp_url);
            File file = new File(temp_url);
            FileSystemView fileSys=FileSystemView.getFileSystemView();
            String name = fileSys.getSystemDisplayName(file);
            double Available = file.getFreeSpace() * 1.0 / Sizes[0];
            double Used = file.getTotalSpace()* 1.0 / Sizes[0] - Available;
            UI.Main.FileProperties properties = new FileProperties(icon, name, Used, Available);
        }
        
        else if(e.getSource() == GoBtn || e.getSource() == GuideText){//通过地址栏进行文件地址跳转
            String url = GuideText.getText();
            if(url.length() > 0){
                File file = new File(url);
                if(file.exists()){
                    stack.push(Cur_URL);
                    Cur_URL = url;
                    Go_There();
                }else{
                    JOptionPane.showConfirmDialog(null, "没有找到该目录", "确认对话框", JOptionPane.YES_OPTION);
                }
            }else{
                Home_List();
            }
        }
        
        else if(e.getSource() == allType){//如果是搜索完切换回显示所有文件，则回到主目录
            isSearching = false;
            chooseType=5;
            showTpye();
            Home_List();
        }
        
        else if(e.getSource() == vedioType || e.getSource() == pictureType || e.getSource() == textType || e.getSource() == musicType){//如果选择了搜索功能
            if(e.getSource()==vedioType)
            {
                chooseType=1;
                showTpye();
            }
            if(e.getSource()==textType)
            {
                chooseType=2;
                showTpye();
            }
            if(e.getSource()==pictureType)
            {
                chooseType=3;
                showTpye();
            }
            if(e.getSource()==musicType)
            {
                chooseType=4;
                showTpye();
            }
            defaultListModel.clear();
            Icon_Counter = 0;
            AllIcons = new Icon[1000010];
            GetAllResults(Cur_URL);
            list.setModel(defaultListModel);
            list.setCellRenderer(new UI.Main.MyCellRenderer(AllIcons));//获取筛选后的新文件列表
        }

        else if(e.getSource()== ViewBtn)
        {
            String prefix = aimFile.substring(aimFile.lastIndexOf('.') + 1);
            System.out.println(aimFile);
            if(VideoType.contains(prefix)||MusicType.contains(prefix))
            {
                VideoPlayer.generate(ViewPanel,aimFile);
                return;
            }
            if(GraphType.contains(prefix))
            {
                GraphDisplay.disPlay(aimFile);
                return;
            }
            JOptionPane.showMessageDialog(
                    this,
                    "This File or Directory can not be viewed",
                    "ERROR",
                    JOptionPane.INFORMATION_MESSAGE);
        }
        else if(e.getSource()==infobtn)
        {
            if (infoPanel!=null)
            this.remove(infoPanel);
            infoPanel=new JPanel();
            this.add(infoPanel);
            infoPanel.setBounds(610,50,600,801);
            
            if(MainForm.Cur_URL=="")
            {
                String temp_url = list.getSelectedValue() + "\\";
                Icon icon = FileIcon.getIcon(temp_url);
                File file = new File(temp_url);
                FileSystemView fileSys=FileSystemView.getFileSystemView();
                String name = fileSys.getSystemDisplayName(file);
                double Available = file.getFreeSpace() * 1.0 / Sizes[0];
                double Used = file.getTotalSpace()* 1.0 / Sizes[0] - Available;
                properties = new FileProperties(icon, name, Used, Available);
                infoPanel.add(properties);
            }
            else
            {
                String temp_url = Cur_URL + list.getSelectedValue() + "\\";
                File file = new File(temp_url);
                Icon icon = FileIcon.getIcon(temp_url);
                String name = list.getSelectedValue();
                long size;
                double final_size;
                long File_Num = 0, Directory_Num = 0;
                int flag = 0;
                String file_size = "";
                System.out.println(temp_url);
                String Create_Time = FileTime.CreateTime(temp_url);
                String Modify_Time = FileTime.UpdateTime(temp_url);
                String Last_Access = FileTime.AccessTime(temp_url);
                
                if(file.isDirectory()){//目录属性初始化所需参数
                    FileInfo DInfo = new FileInfo();
                    size = DInfo.instance.getSize(file);
                    File_Num = DInfo.file_num;
                    Directory_Num = DInfo.dir_num;
                    flag = 1;
                }else{//文件属性初始化所需参数
                    size = file.length();
                }
                
                final_size = 0;
                for(int i = 0; i < Sizes.length; ++i){
                    if(size / Sizes[i] > 0){
                        final_size = size * 1.0 / Sizes[i];
                        DecimalFormat fnum = new DecimalFormat("##0.00");
                        file_size = fnum.format(final_size) + Size_Names[i];
                        break;
                    }
                }
                FileProperties properties;
                if(flag == 1){
                    properties = new FileProperties(icon, name, file_size, File_Num, Directory_Num - 1, temp_url, Create_Time);
                }else{
                    properties = new FileProperties(icon, name, file_size, temp_url, Create_Time, Modify_Time, Last_Access);
                }
                infoPanel.add(properties);
            }
        }
    }
}
